import 'package:get/get.dart';
import 'package:juming_test/action/home_action.dart';
import 'package:juming_test/model/home/home_notice_model.dart';

class HomeNoticeViewModel extends GetxController {
  // 公告栏数据,每页展示两条
  final Rx<List<List<HomeNoticeModel>>> noticeList = Rx([]);

  @override
  onReady() {
    super.onReady();
    _getNoticeList();
  }

  // 获取公告栏数据
  Future<void> _getNoticeList() async {
    List<HomeNoticeModel> allNotices = await HomeAction.fetchNoticeList();
    noticeList.value.clear();
    for (int i = 0; i < allNotices.length; i += 2) {
      int end = (i + 2 < allNotices.length) ? i + 2 : allNotices.length;
      noticeList.value.add(allNotices.sublist(i, end));
    }
    noticeList.refresh();
  }
}
